import React,{Component} from 'react'
import { View } from 'react-native'
import { ListView,TouchableOpacity } from '@shoutem/ui'

import ImagePost from './ImagePost'
import TextPost from './TextPost'
import VideoPost from './VideoPost'

function renderPicRow (data) {
  return (
    <ImagePost
      {...data}
      uri={data.img_src}
      // id={id}
      // username={username}
      // ctime={ctime}
      // desc={desc}
      // uri={img_src}
      // height={height}
      // width={width}
      // resized_url={resized_url}
    />
  )
}

function renderTextRow (data, onFavoritePress, onLikePress) {
  // const { username, ctime, text } = data
  return (
    <TextPost
      {...data}
      onFavoritePress={onFavoritePress}
      onLikePress={onLikePress}
    />
  )
}

function renderVideoRow (data) {
  // const { username, ctime, video_src, poster, desc } = data
  return (
    <VideoPost
      {...data}
      uri={data.video_src}
    />
  )
}

const Posts = (
  {datas, loading, onLoadMore, onRefresh, tag, onFavoritePress, onLikePress}
) => {
  console.log('*********')
  const renderRows = {
    image:renderPicRow, text:renderTextRow, video: renderVideoRow
  }
  let renderRow = renderRows[tag]
  return (
    <View style={{marginTop:50}}>
      <ListView
        data={datas}
        loading={loading}
        renderRow={(data) => renderRow(data, onFavoritePress, onLikePress)}
        onLoadMore={onLoadMore}
        onRefresh={onRefresh}
      />
    </View>
  )
}

export default Posts
